package NGUYENCONGLUAN.BT1;

import java.util.Scanner;

public class PhuongTrinhBac20 {
	int a, b, c;

	public void tinhnghiem() {
		double x1 = 0;
		double x2 = 0;
		double delta = 0;
		Scanner sc = new Scanner(System.in);
		System.out.println("Nhap gia tri a");
		a = sc.nextInt();
		System.out.println("Nhap gia tri b");
		b = sc.nextInt();
		System.out.println("Nhap gia tri c");
		c = sc.nextInt();

		if (a == 0) {
			if (b == 0) {
				if (c == 0)
					System.out.println("phuong trinh vo so nghiem");
				else
					System.out.println("phuong trinh vo nghiem");

			} else {
				x1 = (double) -c / b;
				System.out.println("nghiem la : " + x1);
			}

		} else {

			delta = (b * b) - (4 * a * c);
			if (delta == 0) {
				x1 = -b / (2 * a);
				System.out.println("x1=x2=" + (-b / (2 * a)));
				System.out.println("Phuong trinh co nghiem duy nhat" + x1);
				if (delta < 0) {
					System.out.println("phuong trinh vo nghiem");
				} else if (delta > 0) {
					System.out
							.println("x1=" + (b + Math.sqrt(delta)) / (2 * a));
					System.out.println("x1=" + -(b + Math.sqrt(delta))
							/ (2 * a));
				}
			}

		}
	}
}
